package com.lsfb.signln.Leave;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.lsfb.signln.R;
import com.lsfb.signln.Utils.URLString;
import com.zgscwjm.lsfbbasetemplate.adapter.CommonRecycAdapter;
import com.zgscwjm.lsfbbasetemplate.adapter.ViewHolderRecyc;

import java.util.List;

/**
 * Created by Administrator on 2018/2/10 0010.
 */

public class LeaveListAdapter extends CommonRecycAdapter<LeaveListBean.ListBean> {
    private Context mContext;

    private ItemListener listener;

    public interface ItemListener {
        void onItem(LeaveListBean.ListBean model);
    }

    public LeaveListAdapter(Context context, List<LeaveListBean.ListBean> list, int layoutId, ItemListener listener) {
        super(context, list, layoutId);
        mContext = context;
        this.listener = listener;
    }

    @Override
    public void convert(ViewHolderRecyc holder, final LeaveListBean.ListBean model) {
        if (model.getHeadimg() != null && !model.getHeadimg().isEmpty()) {
            holder.setVisible(R.id.item_img_head, true);
            holder.setVisible(R.id.item_text_head, false);
            holder.setImg(R.id.item_img_head, URLString.IMAGES + model.getHeadimg(), R.mipmap.img_test_head_hui);
        } else {
            holder.setVisible(R.id.item_img_head, false);
            holder.setVisible(R.id.item_text_head, true);
            holder.setText(R.id.item_text_head, model.getName().substring(model.getName().length() - 2, model.getName().length()));
        }
        holder.setText(R.id.item_leave_name, model.getName());
        holder.setText(R.id.item_start_time, model.getStartTime());
        holder.setText(R.id.item_end_time, model.getEndTime());
        holder.setText(R.id.item_leave_days, "共" + String.valueOf(model.getCountDays()) + "天");

        TextView tv_status = holder.getView(R.id.item_leave_status);
        switch (model.getState()) {
            case -3:
                tv_status.setText("已撤销");
                tv_status.setTextColor(mContext.getResources().getColor(R.color.theme_color));
                break;
            case -2:
                tv_status.setText("被拒绝");
                tv_status.setTextColor(mContext.getResources().getColor(R.color.label_red));
                break;
            case -1:
                tv_status.setText("已通过");
                tv_status.setTextColor(mContext.getResources().getColor(R.color.theme_color));
                break;
            default:
                tv_status.setText("待审批");
                tv_status.setTextColor(mContext.getResources().getColor(R.color.theme_color));
                break;
        }

        holder.setOnclick(R.id.item_leave, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onItem(model);
                }
            }
        });
    }
}
